package com.ruoyi.web.controller.ring.app;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.Builder;
import com.ruoyi.ring.domain.RingPhysicalConditionLayout;
import com.ruoyi.ring.domain.dto.PhysicalConditionLayoutQueryDTO;
import com.ruoyi.ring.service.IRingPhysicalConditionLayoutService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 身体状况布局 APP
 * 
 * @author liuwp
 * @date 2025-10-09
 */
@Slf4j
@RestController
@RequestMapping("/ring/app/ring_physical_condition_layout")
public class AppPhysicalConditionLayoutController extends BaseController
{
    @Resource
    private IRingPhysicalConditionLayoutService ringPhysicalConditionLayoutService;

    /**
     * 查询身体状况布局列表 app
     * @param queryDTO
     */
    @GetMapping("/query-layout-list")
    public AjaxResult list(PhysicalConditionLayoutQueryDTO queryDTO)
    {
        long userId = SecurityUtils.getUserId();
        log.info("查询身体状况布局列表: userId={}, param={}", userId, JSON.toJSONString(queryDTO));
        List<RingPhysicalConditionLayout> list = ringPhysicalConditionLayoutService.selectRingPhysicalConditionLayoutList(
                Builder.of(RingPhysicalConditionLayout::new).
                        with(RingPhysicalConditionLayout::setDeviceSn, queryDTO.getDeviceSn()).
                        with(RingPhysicalConditionLayout::setUserId, SecurityUtils.getUserId()).build());
        return AjaxResult.success(list);
    }


    /**
     * 修改身体状况布局  app
     */
    @Log(title = "身体状况布局", businessType = BusinessType.UPDATE)
    @PutMapping("/edit-layout")
    public AjaxResult editLayout(@RequestBody List<RingPhysicalConditionLayout> list)
    {
        return toAjax(ringPhysicalConditionLayoutService.editLayout(list));
    }
}
